- #include <avr/io.h>
- #include <util/delay.h>
- #include <avr/interrupt.h>
- /******************************************************************************/
- int main(void)
- {
- cli();
- DDRD &= ~_BV(DDD0); // set as input
- PORTD |= _BV(PORTD0); // enable pull-up
- DDRB |= _BV(DDD5);
- PORTB |= _BV(PORTB5); // initialize to high
- PCICR |= _BV(PCIE2); // set PCIE2 to enable PCMSK2 scan
- PCMSK2 |= _BV(PCINT16); // set PCINT16 to trigger an interrupt on state change
- sei(); // turn on interrupts
- while (1);
- }
- /******************************************************************************/
- ISR (PCINT2_vect)
- {
- if (PIND & _BV(DDD0))
- PORTB |= _BV(PORTB5);
- else
- PORTB &= ~_BV(PORTB5);
- }
- /******************************************************************************/